﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PPAP.BO;
using System.Data;

namespace PPAP.Web.SearchReport
{
    public partial class GeneralSearch : PageBase
    {
        PPARBO bo = new PPARBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                btnSearch_Click(null, null);
            }
        }

        //状态显示
        public string ShowAuditStatus(string Status)
        {
            string result = "";
            result = "<span style='color:red'>已提交</span>";

            switch (Status.ToLower())
            {
                case "0":
                    result = "<span style='color:blue'></span>";
                    break;
                case "1":
                    result = "<span style='color:red'>PPAR created</span>";
                    break;
                case "2":
                    result = "<span style='color:red'>PPAR submitted</span>";
                    break;
                case "3":
                    result = "<span style='color:red'>Ready for sampling</span>";
                    break;
                case "4":
                    result = "<span style='color:red'>not ready for sampling</span>";
                    break;
                case "5":
                    result = "<span style='color:red'>PPAR circulating</span>";
                    break;
                case "6":
                    result = "<span style='color:blue'>PPAR released</span>";
                    break;
                case "7":
                    result = "<span style='color:blue'>PPAR decided</span>";
                    break;

                default:
                    result = "<span style='color:red'></span>";
                    break;
            }
            return result;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string sql = "";
            if (txtCreateStart.Text.Trim() != "")
                sql += " and trunc(ppardate)>=to_date( '" + txtCreateStart.Text.Trim() + "', 'yyyy-mm-dd ') ";
            if (txtCreateEnd.Text.Trim() != "")
                sql += " and trunc(ppardate)<=to_date( '" + txtCreateEnd.Text.Trim() + "', 'yyyy-mm-dd ') ";
            if (txtSupper.Text.Trim() != "")
                sql += " and s.suppliername like '%"+txtSupper.Text.Trim()+"%' ";
            if (txtQE.Text.Trim() != "")
                sql += " and  quanlityengineer like '%"+txtQE.Text.Trim()+"%' ";
            if (ddlDocument.SelectedValue != "All")
                sql += " and iscapabilitydocument="+ddlDocument.SelectedValue+" ";
            if (ddlPart.SelectedValue != "All")
                sql += " and iscapabilitypart="+ddlPart.SelectedValue+" ";
            if (rbtWait.Checked)
                sql += "and a.status=6 ";
            if (rbtApproved.Checked)
                sql += " and a.status=7 ";
            if (rbtG.Checked)
                sql += " and a.finalresult='G' ";
            if (rbtY.Checked)
                sql += " and a.finalresult='Y' ";
            if (rbtR.Checked)
                sql += " and a.finalresult='R' ";
            if (RadioButton1.Checked)
                sql += " and a.status>=5 ";
            if (RadioButton2.Checked)
                sql += "  and a.status<5 ";
            if (RadioButton3.Checked)
                sql += " and a.id  in(select pparid from samplecard where endtimeplan<sysdate group by pparid) ";
            if (RadioButton4.Checked)
                sql += " and a.id not in(select pparid from samplecard where endtimeplan<sysdate group by pparid) ";
            DataSet ds = bo.GetListForGeneral(sql);
            AspNetPager2.RecordCount = ds.Tables[0].Rows.Count;
            dgList.DataSource = GetPageTable(ds.Tables[0], AspNetPager2.PageSize, AspNetPager2.CurrentPageIndex);
            dgList.DataBind();
        }

        protected void AspNetPager2_PageChanged(object sender, EventArgs e)
        {
            btnSearch_Click(null, null);
        }
    }
}